/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Assignment.Util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author dieptn
 */
public class ConnectionUtil {

    public static Connection getConnection() {
        Connection con = null;
        try {
            Properties prop = new Properties();
            //InputStream input = ConnectionUtil.class.getClass().getResourceAsStream("/Properties/dbConnection.properties");
            InputStream input = ConnectionUtil.class.getResourceAsStream("/Properties/dbConnection.properties");

            //prop.load(new FileInputStream("dbConnection.properties"));
            prop.load(input);
            String driver = prop.getProperty("driver");
            String url = prop.getProperty("url");
            String username = prop.getProperty("username");
            String password = prop.getProperty("password");
            Class.forName(driver);
            con = DriverManager.getConnection(url, username, password);
        } catch (SQLException ex) {
            Logger.getLogger(ConnectionUtil.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ConnectionUtil.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ConnectionUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
        return con;
    }

    public static String getUserFilePath() {
        String filepath = "";
        try {
            Properties prop = new Properties();
            //InputStream input = ConnectionUtil.class.getClass().getResourceAsStream("/Properties/dbConnection.properties");
            InputStream input = ConnectionUtil.class.getResourceAsStream("/Properties/dbConnection.properties");
            //prop.load(new FileInputStream("dbConnection.properties"));
            prop.load(input);
            filepath = prop.getProperty("userxml");
        } catch (IOException e) {
            Logger.getLogger(ConnectionUtil.class.getName()).log(Level.SEVERE, null, e);
        }
        return filepath;
    }

    public static String getBookFilePath() {
        String filepath = "";
        try {
            Properties prop = new Properties();
            //InputStream input = ConnectionUtil.class.getClass().getResourceAsStream("/Properties/dbConnection.properties");
            InputStream input = ConnectionUtil.class.getResourceAsStream("/Properties/dbConnection.properties");
            //prop.load(new FileInputStream("dbConnection.properties"));
            prop.load(input);
            filepath = prop.getProperty("bookxml");
        } catch (IOException e) {
            Logger.getLogger(ConnectionUtil.class.getName()).log(Level.SEVERE, null, e);
        }
        return filepath;
    }

    public static String getNewBookFilePath() {
        String filepath = "";
        try {
            Properties prop = new Properties();
            //InputStream input = ConnectionUtil.class.getClass().getResourceAsStream("/Properties/dbConnection.properties");
            InputStream input = ConnectionUtil.class.getResourceAsStream("/Properties/dbConnection.properties");
            //prop.load(new FileInputStream("dbConnection.properties"));
            prop.load(input);
            filepath = prop.getProperty("newbookxml");
        } catch (IOException e) {
            Logger.getLogger(ConnectionUtil.class.getName()).log(Level.SEVERE, null, e);
        }
        return filepath;
    }

    public static String getOrderFilePath() {
        String filepath = "";
        try {
            Properties prop = new Properties();
            //InputStream input = ConnectionUtil.class.getClass().getResourceAsStream("/Properties/dbConnection.properties");
            InputStream input = ConnectionUtil.class.getResourceAsStream("/Properties/dbConnection.properties");
            //prop.load(new FileInputStream("dbConnection.properties"));
            prop.load(input);
            filepath = prop.getProperty("orderxml");
        } catch (IOException e) {
            Logger.getLogger(ConnectionUtil.class.getName()).log(Level.SEVERE, null, e);
        }
        return filepath;
    }

        public static String getBookOrderFilePath() {
        String filepath = "";
        try {
            Properties prop = new Properties();
            //InputStream input = ConnectionUtil.class.getClass().getResourceAsStream("/Properties/dbConnection.properties");
            InputStream input = ConnectionUtil.class.getResourceAsStream("/Properties/dbConnection.properties");
            //prop.load(new FileInputStream("dbConnection.properties"));
            prop.load(input);
            filepath = prop.getProperty("book_orderxml");
        } catch (IOException e) {
            Logger.getLogger(ConnectionUtil.class.getName()).log(Level.SEVERE, null, e);
        }
        return filepath;
    }
}
